package org.springblade.modules.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.utils.StringPool;
import org.springblade.modules.admin.dto.UserDTO;
import org.springblade.modules.admin.service.AccountManageService;
import org.springblade.modules.admin.vo.UserExtVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

import static org.springblade.core.cache.constant.CacheConstant.USER_CACHE;

/**
 * @Date: 2020/12/28 3:31 下午
 * @Author: Jackey
 * @Description: AccountManageController
 */
@RestController
@Api(value = "成员信息", tags = "成员信息接口")
@RequestMapping("/admin/account_manage")
public class AccountManageController {

	@Autowired
	AccountManageService accountManageService;

	/**
	 * 新增或修改
	 */
	@PostMapping()
	public R submit(@Valid @RequestBody UserDTO userDTO,BladeUser bladeUser) {
		CacheUtil.clear(USER_CACHE);
		userDTO.setTenantId(bladeUser.getTenantId());
		return R.status(accountManageService.submit(userDTO));
	}

//	/**
//	 * 自定义用户列表
//	 * userType: 用户角色类型 0-全部,1-维保员,2-物业
//	 */
//	@GetMapping()
//	@ApiImplicitParams({
//		@ApiImplicitParam(name = "account", value = "账号名", paramType = "query", dataType = "string"),
//		@ApiImplicitParam(name = "realName", value = "姓名", paramType = "query", dataType = "string")
//	})
//	public R<IPage<UserExtVO>> page(@ApiIgnore UserExtVO user, Query query,Integer roleType, BladeUser bladeUser) {
//		IPage<UserExtVO> pages = accountManageService.selectUserPage(Condition.getPage(query), user, roleType, (bladeUser.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID) ? StringPool.EMPTY : bladeUser.getTenantId()));
//		return R.data(pages);
//	}

	/**
	 * 修改
	 */
	@PutMapping("/{id}")
	public R update(@PathVariable Long id, @Valid @RequestBody UserDTO userDTO) {
		userDTO.setId(id);
		CacheUtil.clear(USER_CACHE);
		return R.status(accountManageService.updateUser(userDTO));
	}
}
